from jpype import *
import jpype
import os
import sys

# 解决在linux下执行该程序路径报错问题
curPath = os.path.abspath (os.path.dirname (__file__))
rootPath = os.path.split (curPath)[0]
sys.path.append (rootPath)

class signkey:
    def sign(self, req):
        self.req = req
        jar_path = (r"../common/fdd-1.1-SNAPSHOT-jar-with-dependencies.jar")
        if not jpype.isJVMStarted():
            # startJVM：本地调试使用第一个，提交代码需要注释第一个，使用第二个绝对路径的（crontab下不识别java的默认路径）
            # startJVM (jpype.getDefaultJVMPath(), "-ea", "-Djava.class.path=%s" % jar_path)
            startJVM (r"/usr/java/jdk1.8.0_11/jre/lib/amd64/server/libjvm.so","-ea","-Djava.class.path=%s" % jar_path)

        jprint = java.lang.System.out.println

        instance = JPackage('com').fangddd.ddsign

        key = instance.SignUtil.generateSign (req)
        # jprint(type(key))
        return str(key)
        jpype.shutdownJVM()  # 最后关闭jvm
        # print(str(key))


if __name__ == '__main__':
    a = signkey()
    a.sign ('111111')
    print (a.sign ('111111'))
